﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using BCCommon;
using BCDto.Common.Case.WebsiteCase;
using BCService.Common.Case.WebsiteCase;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace BCTMSRESTful.Controllers.Anonymous
{
    [Route("api/v1/[controller]")]
    [ApiController]
    public class CaseController : BCTMSRESTfulAPIController
    {
        private readonly IWebsiteCaseService websiteCaseService;

        public CaseController(IWebsiteCaseService websiteCaseService)
        {
            this.websiteCaseService = websiteCaseService;
        }

        /// <summary>
        /// 获取官网案例列表。
        /// </summary>
        /// <response code="200">返回官网解决方案列表</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(IEnumerable<WebsiteCaseViewDto>), 200)]
        [AllowAnonymous]
        public IActionResult Get()
        {
            return this.Ok(this.websiteCaseService.GetList());
        }

        #region 获取官网案例（分页）
        /// <summary>
        ///  获取官网案例（分页）
        /// </summary>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取官网案例（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<WebsiteCaseViewDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.websiteCaseService.WebsiteQuery(index, size));
        }
        #endregion
    }
}
